//
//  DZFMDBManager.m
//  DZFoundation
//
//  Created by Darren Zheng on 15/10/13.
//  Copyright © 2015年 Darren Zheng. All rights reserved.
//

#import "DZFMDBManager.h"

@implementation DZFMDBManager

+ (DZFMDBManager *)sharedInstance
{
    static DZFMDBManager *sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] init];
    });
    return sharedInstance;
}

- (FMDatabase *)createDatabaseWithName:(NSString *)strDatabaseName
{
    FMDatabase *database = [FMDatabase databaseWithPath:[FileManager cacheFilePathWithName:strDatabaseName]];
    
    if (![database open])
    {
        NSLog(@"Could not open db.");
        return nil;
    }
    return database;
}

- (FMDatabase *)loadDatabaseFromMainBundleWithName:(NSString *)strName type:(NSString *)styType
{
    FMDatabase *database = [FMDatabase databaseWithPath:[[NSBundle mainBundle] pathForResource:strName ofType:styType]];
    
    if (![database open])
    {
        NSLog(@"Could not open db.");
        return nil;
    }
    return database;
}

@end
